package com.hzw.rest;

import com.hzw.api.ICommodityService;
import com.hzw.common.PageResult;
import com.hzw.entity.Commodity;
import com.hzw.entity.File;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("commodity")
public class CommodityController {
    @Autowired
    ICommodityService commodityService;

    /**
     * 新增商品
     * @param commodity
     */
    @PostMapping("insert")
    @ResponseBody
    public int insert(@RequestBody Commodity commodity) {
        return commodityService.insert(commodity);
    }

    /**
     * 删除商品
     *
     * @param commodity
     */
    @PostMapping("delete")
    @ResponseBody
    public void delById(@RequestBody Commodity commodity) {
        commodityService.delById(commodity);
    }

    /**
     * 更新商品分类信息
     *
     * @param commodity
     */
    @PostMapping("update")
    @ResponseBody
    public void update(@RequestBody Commodity commodity) {
            commodityService.updateById(commodity);
    }

    /**
     * 查询商品
     * @param commodity
     * @return
     */
    @PostMapping("select")
    @ResponseBody
    public List<Commodity> select(@RequestBody Commodity commodity) {
        return commodityService.select(commodity);
    }

    /**
     * 分页查询
     *
     * @return
     */
    @PostMapping("pageSelect")
    @ResponseBody
    public PageResult<Commodity> pageSelect(@RequestBody Commodity commodity) {
        return commodityService.pageSelect(commodity);
    }

}
